#!/usr/bin/env python
# coding=utf-8

# 导入Python标准日志模块
import datetime
import logging

# 从Python SDK导入BOS配置管理模块以及安全认证模块
import os

from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials

# 设置BosClient的Host，Access Key ID和Secret Access Key
bos_host = "gz.bcebos.com"
access_key_id = "*********"
secret_access_key = "********"

# 设置日志文件的句柄和日志级别
logger = logging.getLogger('baidubce.http.bce_http_client')
today = datetime.datetime.now()
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
dir_path = os.path.join(BASE_DIR, 'logs/bos')
file_path = os.path.join(BASE_DIR,
                         "logs/bos/bos_{}_{}_{}_{}.log".format(today.year, today.month, today.day, today.hour))

if not os.path.isdir(dir_path):  # 无文件夹时创建
    os.makedirs(dir_path)
if not os.path.isfile(file_path):  # 无文件时创建
    fd = open(file_path, mode="a", encoding="utf-8")
    fd.close()
else:
    pass
fh = logging.FileHandler(file_path)
fh.setLevel(logging.DEBUG)

# 设置日志文件输出的顺序、结构和内容
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(fh)

# 创建BceClientConfiguration
config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), endpoint=bos_host)
